/**
******************************************************************************
* @file    main.c
* @author  AE Team
* @version V1.3.9
* @date    28/08/2019
* @brief   This file provides all the main firmware functions.
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2019 MindMotion</center></h2>
*/#include "sys.h"
#include "delay.h"
#include "uart.h"
#include "led.h"

#include <k_api.h>
#include <k_task.h>
#include <stdio.h>
#include <stdlib.h>

#define DEMO_TASK_STACKSIZE    256 //256*cpu_stack_t = 1024byte
#define DEMO_TASK_PRIORITY     20

extern void stm32_soc_init(void);
static ktask_t demo_task_obj;
cpu_stack_t demo_task_buf[DEMO_TASK_STACKSIZE];

static ktask_t Test_Task_t;
static ktask_t Led_Task_t;
cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];

void Led1_Task(void* a)
{

	while(1)
	{
        LED3 = !LED3;
        LED4 = !LED4;
		krhino_task_sleep(6*RHINO_CONFIG_TICKS_PER_SECOND);
	}
}	
void Led_Task(void* a)
{
	while(1)
	{
        LED1 = !LED1;
        LED2 = !LED2;
		krhino_task_sleep(3*RHINO_CONFIG_TICKS_PER_SECOND);
	}
}
void DELAY_Init(void)
{
    if (SysTick_Config(SystemCoreClock / 1000)) {
        while (1);
    }
    NVIC_SetPriority(SysTick_IRQn, 0x0);
}
void demo_task(void *arg)
{
#ifndef CONFIG_AOS_CLI
 //   int count = 0;
#endif

    LED_Init();
    DELAY_Init();
    uart_initwBaudRate(115200);
    printf("demo_task here!\n");
    printf("rhino memory is %d!\n", krhino_global_space_get());
    
    if(krhino_task_create(&Led_Task_t,"LED_TASK",0,DEMO_TASK_PRIORITY, 
        50, demo_task_buf1, DEMO_TASK_STACKSIZE, Led1_Task, 1)!=0)
		printf("Led task create faild\n");
	if(krhino_task_create(&Test_Task_t,"Test_Task",0,DEMO_TASK_PRIORITY, 
        50, demo_task_buf2, DEMO_TASK_STACKSIZE, Led_Task, 1)!=0)
		printf("Test task create faild\n");
}

void SysTick_Handler(void)
{			
  krhino_intrpt_enter();
  krhino_tick_proc();
  krhino_intrpt_exit();	
}
int main(void)
{
    krhino_init();
   
#ifdef CONFIG_AOS_CLI
    extern int aos_cli_init(void);
    aos_cli_init();
#endif

    krhino_task_create(&demo_task_obj, "demo_task", 0,DEMO_TASK_PRIORITY, 
        50, demo_task_buf, DEMO_TASK_STACKSIZE, demo_task, 1);

    krhino_start();
    
    return 0;
}

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/*-------------------------(C) COPYRIGHT 2019 MindMotion ----------------------*/

